//
//  ZYMiyoshiBankController.m
//  BestLearning
//
//  Created by Ethan on 2017/9/12.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "ZYMiyoshiBankController.h"
#import "ZYStarMoneyRechargeController.h"
#import "ZYCurrencyExchangeController.h"
#define kCell @"cell"
#import "IncomeStatementVC.h"
#import "RecevieListVC.h"
#import "ZYMoonSegmentController.h"
#import "ZYAddStrongCouseDetailController.h"

@interface ZYMiyoshiBankController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UIView *allView;
@property (nonatomic,strong) UIImageView *photoImageView;
@property (nonatomic,strong) UIButton *backButton;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataSource;
@property (nonatomic,strong) NSMutableArray *dataTowSource;
@property (nonatomic,strong) UILabel *starLabel;//星币数
@property (nonatomic,strong) UILabel *redLabel;//红花数
@end

@implementation ZYMiyoshiBankController


- (NSMutableArray *)dataTowSource {
    
    if (_dataTowSource == nil) {
        self.dataTowSource = [NSMutableArray arrayWithObjects:@"收入明细", @"优惠卡券",nil];
    }
    
    return _dataTowSource;
    
}


- (NSMutableArray *)dataSource {
    
    if (_dataSource == nil) {
        
        self.dataSource = [NSMutableArray arrayWithObjects:@"星币兑换", nil];
    }
    return _dataSource;
    
}






- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.title = @"三好银行";
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    UIBarButtonItem *liftItem = [UIBarButtonItem itemWithTargat:self action:@selector(itemAction) image:@"icon_back_student_sign" highImage:@"icon_back_student_sign"];
    
    self.navigationItem.leftBarButtonItem =liftItem;
    
    
    
    
    
    [self setNetWork];
    [self setUpSuperView];
    
}



- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ColorRGB(51,51,51)}];
    [self.navigationController.navigationBar setBackgroundImage:[LLTools createImageWithColor:ColorRGB(255, 255, 255)] forBarMetrics:(UIBarMetricsDefault)];
}

- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ColorRGB(255,255,255)}];
    [self.navigationController.navigationBar setBackgroundImage:[LLTools createImageWithColor:ColorRGB(47, 204, 138)] forBarMetrics:(UIBarMetricsDefault)];;

}




#pragma mark ----- 收入说明方法的实现
- (void)itemAction{

//    IncomeStatementVC *VC = [[IncomeStatementVC alloc] init];
//    [self.navigationController pushViewController:VC animated:YES];

   // [self.navigationController pushViewController:[ZYAddStrongCouseDetailController new] animated:YES];

    [self.navigationController popViewControllerAnimated:YES];

}


- (void)setNetWork{
    
    NSString *url = [NSString stringWithFormat:@"user.do?action=getMyInfoAndRecharge"];
    
    NSLog(@"%@  %@",LLBaseURLs(url),[AccountTool shareAccountTool].currentAccount.authCode);
    
    
    [NetManager Get:LLBaseURLs(url) Auth:YES Params:nil Success:^(id Obj) {
        if ([[Obj valueForKey:@"code"] integerValue] == 1000) {
            
            NSDictionary *t = [Obj valueForKey:@"t"];
            
            self.starLabel.text = [NSString stringWithFormat:@"%ld",[[t valueForKey:@"money"]  integerValue]];
            self.redLabel.text = [NSString stringWithFormat:@"%ld",[[t valueForKey:@"flowers"] integerValue]];
        }
    } Fail:^(NSError *Error) {
        
    }];
    
    
   
    
    
    
}


- (void)setUpSuperView{
    
    self.allView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 180)];
    self.allView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.allView];
    
    UIImageView *photoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 180)];
    photoImageView.image = [UIImage imageNamed:@"bg_bank_default1"];
    photoImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.allView addSubview:photoImageView];
    
    

    self.starLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 130, kScreenWidth/2, 20)];
    self.starLabel.font = [UIFont systemFontOfSize:25];
    self.starLabel.textAlignment = NSTextAlignmentCenter;
    self.starLabel.textColor = ColorRGB(253, 253, 253);
  
    [photoImageView  addSubview:self.starLabel];
    
    UILabel *labelOne = [[UILabel alloc]initWithFrame:CGRectMake(self.starLabel.frame.origin.x , self.starLabel.frame.origin.y +self.starLabel.frame.size.height, self.starLabel.frame.size.width, self.starLabel.frame.size.height)];
    labelOne.font = [UIFont systemFontOfSize:11];
    labelOne.textColor= ColorRGB(253, 253, 253);
    labelOne.textAlignment = NSTextAlignmentCenter;
    labelOne.text = @"星币（个）";
    [photoImageView addSubview:labelOne];
    
    
    self.redLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.starLabel.frame.origin.x + self.starLabel.frame.size.width, self.starLabel.frame.origin.y, self.starLabel.frame.size.width, self.starLabel.frame.size.height)];
    
    self.redLabel.font = [UIFont systemFontOfSize:25];
    self.redLabel.textAlignment = NSTextAlignmentCenter;
    self.redLabel.textColor = ColorRGB(253, 253, 253);
    [photoImageView addSubview:self.redLabel];
    
    
    UILabel *labelTow = [[UILabel alloc]initWithFrame:CGRectMake(labelOne.frame.origin.x + labelOne.frame.size.width,labelOne.frame.origin.y,labelOne.frame.size.width,labelOne.frame.size.height)];
    labelTow.font = [UIFont systemFontOfSize:11];
    labelTow.textColor= ColorRGB(253, 253, 253);
    labelTow.textAlignment = NSTextAlignmentCenter;
    labelTow.text = @"红花（朵）";
    [photoImageView addSubview:labelTow];
    
    
    
    
    
    
    
    
    
    
    
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.allView.frame.origin.y + self.allView.frame.size.height, kScreenWidth, kScreenHeight - 200)];
    [self.tableView registerClass:[UITableViewCell  class] forCellReuseIdentifier:kCell];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    
    [self.view addSubview:self.tableView];
    
    
    
    
    
}



 #pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (0 == section) {
        return self.dataSource.count;
    }else{
        
        return self.dataTowSource.count;
    }
    
   
}









- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCell forIndexPath:indexPath];
    
    if (0 == indexPath.section) {
        
        cell.textLabel.text = self.dataSource[indexPath.row];
       
    }else{
        
         cell.textLabel.text = self.dataTowSource[indexPath.row];
    }
    
    
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.textLabel.textColor = ColorRGB(51, 51, 51);
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    return cell;
}





- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    if (0 == indexPath.section) {
        
        if (0 == indexPath.row) {
            ZYCurrencyExchangeController *vc = [ZYCurrencyExchangeController new];
            vc.backPop = ^{
                [self setNetWork];
            };
            
            [self.navigationController pushViewController:vc animated:YES];
            
        }
//        else{
//             [self.navigationController pushViewController:[ZYStarMoneyRechargeController new] animated:YES];
//        }
        
        
    }else{
        
        if (0 == indexPath.row) {
            RecevieListVC *VC = [[RecevieListVC alloc] init];
            [self.navigationController pushViewController:VC animated:YES];
        }else{
            ZYMoonSegmentController *VC = [[ZYMoonSegmentController alloc] init];
            [self.navigationController pushViewController:VC animated:YES];
        }
        
     
    }

    
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    if (0 == section) {
        return 20;
    }else{  
        return 0;
    }
    
    
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 20)];
    view.image =[UIImage imageNamed:@"add_seg_large_default"];
    return view;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return 60;
    
}






//将要显示Cell的时候执行该代理方法

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //补齐分割线、两边延长
    
    [self replenishLine:cell];
    
}

//补齐分割线、两边延长

-(void)replenishLine:(UIView *)view{
    
    if ([view respondsToSelector:@selector(setSeparatorInset:)]){
        
        [(UITableViewCell *)view setSeparatorInset:UIEdgeInsetsZero];//注意这里：必须将view强制转换成（UITableViewCell ＊）类，不然会报错。
        
    }
    
    if ([view respondsToSelector:@selector(setLayoutMargins:)])
        
    {
        
        [view setLayoutMargins:UIEdgeInsetsZero];
        
    }
    
}









@end
